package com.zhongen.oa.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongen.common.core.util.R;
import com.zhongen.common.log.annotation.SysLog;
import com.zhongen.oa.entity.ContractDetailEntity;
import com.zhongen.oa.service.ContractDetailService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 合同明细表
 *
 * @author Code Generator
 * @date 2024-01-19 14:33:49
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/contractDetail")
@Tag(description = "contractDetail", name = "合同明细表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ContractDetailController {

	private final ContractDetailService contractDetailService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param contractDetail 合同明细表
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('oa_projectContract_view')")
	public R getContractDetailPage(@ParameterObject Page page, @ParameterObject ContractDetailEntity contractDetail) {
		return R.ok(contractDetailService.getContractDetailPage(page, contractDetail));
	}

	/**
	 * 通过id查询合同明细表
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('oa_projectContract_view')")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(contractDetailService.getById(id));
	}

	/**
	 * 新增合同明细表
	 * @param contractDetail 合同明细表
	 * @return R
	 */
	@Operation(summary = "新增合同明细表", description = "新增合同明细表")
	@SysLog("新增合同明细表")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('oa_projectContract_add')")
	public R save(@RequestBody ContractDetailEntity contractDetail) {
		return R.ok(contractDetailService.save(contractDetail));
	}

	/**
	 * 修改合同明细表
	 * @param contractDetail 合同明细表
	 * @return R
	 */
	@Operation(summary = "修改合同明细表", description = "修改合同明细表")
	@SysLog("修改合同明细表")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('oa_projectContract_edit')")
	public R updateById(@RequestBody ContractDetailEntity contractDetail) {
		return R.ok(contractDetailService.updateById(contractDetail));
	}

	/**
	 * 通过id删除合同明细表
	 * @param ids id列表
	 * @return R
	 */
	@Operation(summary = "通过id删除合同明细表", description = "通过id删除合同明细表")
	@SysLog("通过id删除合同明细表")
	@DeleteMapping
	@PreAuthorize("@pms.hasPermission('oa_projectContract_del')")
	public R removeById(@RequestBody Long[] ids) {
		return R.ok(contractDetailService.removeBatchByIds(CollUtil.toList(ids)));
	}

}
